﻿Imports System.Data
Imports System.Data.SqlClient
Imports Entidad

Public Class NotaCreditoIngresoDetalleDatos

    Sub registrarNotaCreditoIngresoDetalle(ByVal ncid As NotaCreditoIngresoDetalle)
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "INSERT INTO Documento_Cliente_Almacen_Detalle(CIA_Cli,SUC_Cli,TDOC_Cli,DCI_Codigo_Cli," &
                              "DCD_Codigo,Codigo_Cli,CIA_Alm,SUC_Alm,TDOC_Alm,DCA_Codigo_Alm,DAD_Codigo,Codigo_Alm,DCAD_Est,DCAD_Activo) " &
                              "VALUES('01','01',@tdoccli,@dcicodigo,@dcdcodigo,@codcli,'01','01',@tdocalm,@dcacodigo,@dadcodigo,@codalm,'02','1')"
        Dim comando As New SqlCommand
        With comando
            .Connection = coneccion
            .CommandText = query
            .Parameters.AddWithValue("@tdoccli", ncid.TDOC_Cli)
            .Parameters.AddWithValue("@dcicodigo", ncid.DCI_Codigo_Cli)
            .Parameters.AddWithValue("@dcdcodigo", ncid.DCD_Codigo)
            .Parameters.AddWithValue("@codcli", ncid.Codigo_Cli)
            .Parameters.AddWithValue("@tdocalm", ncid.TDOC_Alm)
            .Parameters.AddWithValue("@dcacodigo", ncid.DCA_Codigo_Alm)
            .Parameters.AddWithValue("@dadcodigo", ncid.DAD_Codigo)
            .Parameters.AddWithValue("@codalm", IIf(ncid.Codigo_Alm.ToString.Trim = "", "00", ncid.Codigo_Alm))
            .ExecuteNonQuery()
        End With
        coneccion.Close()
    End Sub

    Sub actualizarNotaCreditoIngresoDetalle(ByVal ncid As NotaCreditoIngresoDetalle)
        Dim conex As New Conexion
        Dim coneccion As SqlConnection = conex.conectar()
        coneccion.Open()
        Dim query As String = "UPDATE Documento_Cliente_Almacen_Detalle " &
                              "SET DCD_Codigo = @dcdcodigo, Codigo_Cli = @codcli, " &
                              "DAD_Codigo = @dadcodigo, Codigo_Alm = @codalm, DCAD_Est = '02', DCAD_Activo = '1' " &
                              "WHERE TDOC_Cli = @tdoccli AND DCI_Codigo_Cli = @dcicodigo " &
                              "AND TDOC_Alm = @tdocalm AND DCA_Codigo_Alm = @dcacodigo"
        Dim comando As New SqlCommand
        With comando
            .Connection = coneccion
            .CommandText = query
            .Parameters.AddWithValue("@tdoccli", ncid.TDOC_Cli)
            .Parameters.AddWithValue("@dcicodigo", ncid.DCI_Codigo_Cli)
            .Parameters.AddWithValue("@dcdcodigo", ncid.DCD_Codigo)
            .Parameters.AddWithValue("@codcli", ncid.Codigo_Cli)
            .Parameters.AddWithValue("@tdocalm", ncid.TDOC_Alm)
            .Parameters.AddWithValue("@dcacodigo", ncid.DCA_Codigo_Alm)
            .Parameters.AddWithValue("@dadcodigo", ncid.DAD_Codigo)
            .Parameters.AddWithValue("@codalm", IIf(ncid.Codigo_Alm.ToString.Trim = "", "00", ncid.Codigo_Alm))
            .ExecuteNonQuery()
        End With
        coneccion.Close()
    End Sub

End Class
